# -*- coding: utf-8 -*-
import os
import psycopg2
import psycopg2.extras
import logging

DATABASE_URL = os.environ.get('DATABASE_URL','postgresql://postgres:8964@localhost:5432/postgres')

if not DATABASE_URL:
    logging.critical("致命错误: 环境变量 DATABASE_URL 未设置！")
    raise ValueError("环境变量 DATABASE_URL 未设置！")

def get_db_connection():
    try:
        conn = psycopg2.connect(DATABASE_URL)
        return conn
    except psycopg2.OperationalError as e:
        logging.error(f"数据库连接失败: {e}")
        raise